import { IFeidaoAiMobile } from '@dfeidao/atom-mobile/interfaces';
import remove from '@dfeidao/atom-mobile/local/remove';
import set from '@dfeidao/atom-mobile/local/set';
import nodejs from '@dfeidao/atom-mobile/msg/nodejs';
import render from '@dfeidao/atom-mobile/render/render';
import whoami_getparams from '../atom/whoami_getparams';

export default async function a001(fd: IFeidaoAiMobile) {
	// 个人作业
	remove(fd, 'obj');
	remove(fd, 'zymc');
	remove(fd, 'zynr');
	// 系统参数:username:教师姓名,usercode:教师编号
	// 备注:"个性化设置"值 0:全班,1:个人, "作业类型":0:手动布置,1:题库抽题,
	const user = await whoami_getparams(fd) as { userinfo: object, params: object };
	// console.log(user, '--------user--------');
	const user_whoami = user.userinfo as { productid: string, usercode: string, user_name: string };
	const productid = user_whoami.productid;
	set(fd, "productid", productid);

	const p = user.params as { teacher_no: string; teacher_name: string; productid: string; };
	const teacher_no = p.teacher_no;
	const teacher_name = p.teacher_name;
	set(fd, 'teacher_no', teacher_no);
	set(fd, 'teacher_name', teacher_name);

	const res = await nodejs<Array<{}>>('app-personal-work/s001', { productid, teacher_no });
	// console.log(res, '-------res------------');

	const arr = new Array();
	res.forEach((v: { _id: string; student_name: string; }) => {
		arr.push(v.student_name);
	});

	set(fd, 'data', res);
	// set(fd, 'arr', arr);

	render(fd, { dt: arr, index: -1, zymc: '', zynr: '' });
}
